commonlibsse_ng\re\n/NiRTTI.rs
1use core::ffi::c_char;
2
3#[repr(C)]
4pub struct NiRTTI {
5 name: *const c_char,
6 base_rtti: *const NiRTTI,
7}
8const _: () = assert!(std::mem::size_of::<NiRTTI>() == 16);
9
10impl NiRTTI {
11 #[inline]
12 pub const fn get_name(&self) -> *const c_char {
13 self.name
14 }
15
16 #[inline]
17 pub const fn get_base_rtti(&self) -> *const Self {
18 self.base_rtti
19 }
20
21 #[inline]
22 pub fn is_kind_of(&self, rtti: *const Self) -> bool {
23 let mut iter = self as *const Self;
24 while !iter.is_null() {
25 if iter == rtti {
26 return true;
27 }
28 iter = unsafe { (*iter).get_base_rtti() };
29 }
30 false
31 }
32}
33
34// // Downcast equivalent
35// pub fn netimmerse_cast<To, From>(a_from: *const From) -> Option<*const To>
36// where
37// To: 'static,
38// From: 'static,
39// {
40// if a_from.is_null() {
41// return None;
42// }
43
44// let to_rtti: *const NiRTTI = &To::Ni_RTTI; // This assumes you have a `Ni_RTTI` defined for each type.
45// let mut from_rtti = unsafe { (*a_from).get_rtti() };
46
47// while !from_rtti.is_null() {
48// if from_rtti == to_rtti {
49// return Some(a_from as *const To);
50// }
51// from_rtti = unsafe { (*from_rtti).get_base_rtti() };
52// }
53
54// None
55// }